package com.sxc.response;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/s03")
public class Servlet03 extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        // 设置服务端的编码
//        resp.setCharacterEncoding("UTF-8");
//        // 设置客户端的编码
//        resp.setHeader("content-type", "text/html;charset=UTF-8");

        //同时设置编码
        resp.setContentType("text/html;charset=UTF-8");

        ServletOutputStream os = resp.getOutputStream();
        os.write("<h2>你好</h2>".getBytes("UTF-8"));
    }
}
